package com.heaven.jane.sourcegenerator.business.${name}.service;

import java.util.Optional;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.heaven.jane.sourcegenerator.business.${name}.dao.${name?capitalize}Repository;
import com.heaven.jane.sourcegenerator.business.${name}.dao.${name?capitalize}Spec;
import com.heaven.jane.sourcegenerator.business.${name}.domain.${name?capitalize};
import com.heaven.jane.sourcegenerator.business.${name}.domain.${name?capitalize}Vo;

/**
 * 用户业务类
 * @author heaven
 *
 */
@Service
public class ${name?capitalize}ServiceImpl implements ${name?capitalize}Service{
	
	@Autowired
	private ${name?capitalize}Repository ${name}Repository;
	
	@Override
	public Page<${name?capitalize}> list(Optional<${name?capitalize}Vo> condition, Pageable pageable) {
		Page<${name?capitalize}> ${name}s = ${name}Repository.findAll(${name?capitalize}Spec.builder().condition(condition).build(), pageable);
		return ${name}s;
	}

	@Override
	public ${name?capitalize} save(${name?capitalize}Vo data) {
		${name?capitalize} target = new ${name?capitalize}();
		BeanUtils.copyProperties(data, target);
		${name}Repository.save(target);
		return target;
	}

	@Override
	public void delete(${name?capitalize}Vo data) {
		${name?capitalize} target = new ${name?capitalize}();
		BeanUtils.copyProperties(data, target);
		${name}Repository.delete(target);
	}
}
